package com.geezdata.cps.base.utils;

import org.apache.commons.codec.digest.DigestUtils;

import java.io.IOException;
import java.io.InputStream;

public class Md5Util {
    public final static String DIGEST_TYPE = "MD5";
    public final static String DEFAULT_ENCODING = "UTF-8";


    /**
     * MD5签名
     *
     * @param value
     *
     * @return
     */
    public static String md5(String value) {
        return md5("" , value);
    }

    /**
     * MD5签名
     *
     * @param key
     * @param value
     *
     * @return
     */
    public static String md5(String key, String value) {
        return DigestUtils.md5Hex(key + value);
    }

    public static String md5(InputStream is) throws IOException{
        return DigestUtils.md5Hex(is);
    }

    public static String md5(byte[] bytes) throws IOException {
        return DigestUtils.md5Hex(bytes);
    }
}
